package cn.lcl.service.impl;

import cn.lcl.bean.PageBean;
import cn.lcl.dao.IStudentDao;
import cn.lcl.factory.DaoFactory;
import cn.lcl.bean.po.Student;
import cn.lcl.service.IAdminService;
import cn.lcl.util.JdbcUtils;
import cn.lcl.util.Session;
import org.apache.log4j.Logger;

import java.sql.SQLException;
import java.util.List;

/**
 * 跟管理员有关的相关服务
 * Created by licho on 2017/8/16 0016.
 */
public class AdminServiceImpl implements IAdminService {
    private Logger log= Logger.getLogger(AdminServiceImpl.class);
    private IStudentDao dao= DaoFactory.getDaoInstance(IStudentDao.class);//获取StudentDao持久岑操作

    @Override
    public PageBean<Student> showStuLists() {
        Session session= JdbcUtils.getThreadSession();
        session.beginTransaction();//重要
        PageBean<Student> result=null;
        try{
            result=dao.getPageList();
            session.commit();//重要
        } catch (SQLException e) {
            session.rollback();
            e.printStackTrace();
        }finally {
            session.close();//重要
        }
        return result;
    }

    @Override
    public boolean deleteStu(Long sid) {
        boolean flag=false;
        Session session=JdbcUtils.getThreadSession();
        session.beginTransaction();
        try {
            flag=dao.delete(sid);
            session.commit();
        } catch (SQLException e) {
            session.rollback();
            e.printStackTrace();
        }finally {
            session.close();
        }
        return flag;
    }

    @Override
    public boolean updateStu(Student stu) {
        return false;
    }
}
